#ifndef SEQIOT_MQTT_H
#define SEQIOT_MQTT_H

#include <mosquitto.h>
#include "model.h"
#include "../hisdata/hisdata.h"


//MQTT数据发送计划
typedef struct _mqtt_handler_t {
    struct mosquitto *mosq;

    int (*on_device)(struct _mqtt_handler_t *, device_t *device);

    char *ps;
    char *pe;
    char topic[128];
    char payload[4096];
} mqtt_handler_t;

int mqtt_write(mqtt_handler_t *handler, const char *topic, void *payload, int len);

int mqtt_flush(mqtt_handler_t *handler, const char *topic);

void sched_mqtt_segment(mqtt_handler_t *handler, data_catalog_e catalog, device_t *device, segment_e segment);

void sched_mqtt_device(mqtt_handler_t *handler, data_catalog_e catalog, device_t *device);

void sched_mqtt_channel(mqtt_handler_t *handler, data_catalog_e catalog, channel_t *channel);

void sched_mqtt_catalog(mqtt_handler_t *handler, seqiot_t *seqiot);

//数据上报
int publish_scada(mqtt_handler_t *handler, device_t *device);

int publish_packet(mqtt_handler_t *handler, device_t *device);

int publish_scada_aliot(const float *value, const char *topic, mqtt_handler_t *handler, uint16_t dev_id,
                        block_t *block_send, const uint32_t *timestamp, tag_header_t *tag_send);

#endif //SEQIOT_MQTT_H
